package practise.alogrithm.hundredInterviewQuestions.secondTime;

/**
 * Created by Richard on 7/27/2014.
 */
public class PowerANumber {
    public Double power(Integer base, Integer exponent){
        if(exponent==0){
            return 1d;
        }
        Double resule = power(base,exponent/2);// there we cannot use bit operation, as the exponent might be negative
        resule*=resule;
        if((exponent & 0x1)!=0){
            if(exponent>0)
                resule*=base;
            else
                resule/=base;
        }
        return resule;
    }

    public static void main(String[] args){
        System.out.println("result: "+new PowerANumber().power(2,-2));
    }
}
